export const listToTree = (data) => {
  let map = {}
  let tree = []
  data.forEach((node) => {
    map[node.permNo] = node
    node.children = []
  })
  // * obj -> {1001: {id: 1001, parentId: 0, name: 'AA'}, 1002: {...}}
  data.forEach((node) => {
    const parent = map[node.parentNo]
    if (parent) {
      // * 当前项有父节点
      map[node.parentNo].children.push({
        id: node.id,
        value: node.permNo,
        label: node.permName,
        children: node.children
      })
    } else {
      // * 当前项没有父节点 -> 顶层
      tree.push({
        id: node.id,
        value: node.permNo,
        label: node.permName,
        children: node.children
      })
    }
  })
  return tree
}

export const listToList = (data) => {
  const list = []
  data.forEach((node) => {
    list.push({
        key: node.id,
        label: node.jobName,
      })
  })
  return list
}